package cn.gxa.edu_adm.servlet;

import cn.gxa.edu_adm.bean.Course;
import cn.gxa.edu_adm.commn.model.ResultData;
import cn.gxa.edu_adm.service.CourseService;
import cn.gxa.edu_adm.service.impl.CourseServiceImpl;
import cn.gxa.edu_adm.utils.StringUtils;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(urlPatterns = "/courseSelect")
public class CourseSelectServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       //前端参数
        Integer  page= StringUtils.formatInteger(request.getParameter("page"));
        Integer  limit= StringUtils.formatInteger(request.getParameter("limit"));
        String  name= StringUtils.formatString(request.getParameter("name"));
        Integer  courseType= StringUtils.formatInteger(request.getParameter("type"));
        Double  startSocre= StringUtils.formatDouble(request.getParameter("startSocre"));
        Double  endSocre= StringUtils.formatDouble(request.getParameter("endSocre"));
        //操作层
        CourseService service=new CourseServiceImpl();
        //数据库验证
        ResultData resultData=service.findByManyWhere(page,limit,name,courseType,startSocre,endSocre);
        System.out.println(JSON.toJSONString(resultData));
        //响应给前端
        PrintWriter writer = response.getWriter();
        writer.print(JSON.toJSONString(resultData));
        writer.close();



    }
}
